package com.gxuwz.endrskyweather;

import android.os.Bundle;
import androidx.appcompat.app.AppCompatActivity;
import androidx.fragment.app.Fragment;
import androidx.fragment.app.FragmentTransaction;
import com.google.android.material.bottomnavigation.BottomNavigationView;

public class MainContainerActivity extends AppCompatActivity {

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        // 设置状态栏颜色
        getWindow().setStatusBarColor(getResources().getColor(R.color.black));
        // 隐藏ActionBar
        if (getSupportActionBar() != null) {
            getSupportActionBar().hide();
        }
        setContentView(R.layout.activity_main_container);

        // 初始化底部导航
        BottomNavigationView bottomNav = findViewById(R.id.bottom_navigation);
        // 设置导航栏背景色
        //bottomNav.setBackgroundColor(getResources().getColor(R.color.bottom_nav_bg));
        bottomNav.setOnNavigationItemSelectedListener(item -> {
            Fragment selectedFragment = null;
            
            switch (item.getItemId()) {
                case R.id.nav_weather:
                    selectedFragment = new WeatherFragment();
                    break;
                case R.id.nav_city:
                    selectedFragment = new CityManagerFragment();
                    break;
                case R.id.nav_info:
                    selectedFragment = new AppInfoFragment();
                    break;
            }
            
            if (selectedFragment != null) {
                getSupportFragmentManager().beginTransaction()
                    .replace(R.id.fragment_container, selectedFragment)
                    .commit();
            }
            
            return true;
        });

        // 默认加载天气预报Fragment
        if (savedInstanceState == null) {
            bottomNav.setSelectedItemId(R.id.nav_weather);
        }
    }
}
